import { routerRedux } from 'dva/router';
import {
    getMonitorInfo
} from '../services/monitorService';
import moment from 'moment';

const initialState = {
    monitorInfo:{},
    currentPage:1,
    total:0,
    tplList:[],
    selectedIds:[],
    userList:[],
    optional:{},
};

export default {
    namespace: 'monitor',
    state: initialState,
    effects: {
        *fetchMonitorInfo(action, { call, put, select }){
            let { user:{ companyId }} = yield select();
            let { data, code, message } = yield call(getMonitorInfo, { companyId });
            if ( code === 200 ) {
                yield put({ type:'getMonitorInfoResult', payload:{ data }});
            }
        },
        
    },
    reducers: {
        getMonitorInfoResult(state, { payload:{ data }}){
            let { localCOP, localChilledWaterFlow, localEER, localInstantaneousCC, localInstantaneousSaveEle, localMonthCoal, localMonthCumulativeCC, localMonthEleUsage, localPower,
                sevenDayCOPList, sevenDayEERList, sevenDayEleUsageList
            } = data;
            let infoList = [];
            infoList.push({ title:'本月碳排放', value:localCOP || 0, unit:'tco2e'});
            infoList.push({ title:'本月标煤', value:localMonthCoal || 0, unit:'t' });
            infoList.push({ title:'当前功率', value:localPower || 0, unit:'kw' });
            infoList.push({ title:'当前冷冻水流量', value:localChilledWaterFlow || 0, unit:'m³/h' });
            infoList.push({ title:'当前瞬时流量', value:localInstantaneousCC || 0, unit:'GJ' });
            infoList.push({ title:'本月累计制冷量', value:localMonthCumulativeCC || 0, unit:'GJ' });
            data.infoList = infoList;
            return { ...state, monitorInfo:data };
        },
        reset(){
            return initialState;
        }
    }
};
